using UnityEngine;

namespace Gj
{
    public class TouchItemHelper : NodeHelper
    {
        public GameObject item;
        public GameObject hide;
        public NodeHelper[] touchItemList;
        public Vector3 offset;
        public bool isFixed;
        public bool isDrag;
        private Vector3 position;

        public void SetPosition(Vector3 p)
        {
            position = p;
        }

        public void Show()
        {
            if (item != null)
            {
                item.gameObject.SetActive(true);
            }
            else
            {
                gameObject.SetActive(true);
            }
            if (hide != null) hide.gameObject.SetActive(false);
            for(int i = 0; i < touchItemList.Length; i ++)
            {
                touchItemList[i].SetData(true);
            }
            if (isFixed)
                transform.position = position + (offset * SystemInput.scale);
            else if(isDrag)
                Drag();
        }

        public void Hide()
        {
            if (item != null)
            {
                item.gameObject.SetActive(false);
            }
            else
            {
                gameObject.SetActive(false);
            }
            if (hide != null) hide.gameObject.SetActive(true);
            for(int i = 0; i < touchItemList.Length; i ++)
            {
                touchItemList[i].SetData(false);
            }
        }

        public void Drag()
        {
            if (!isDrag) return;
            transform.position = SystemInput.cp;
        }
    }
}